#include "opengl_helper.h"
#include <glib.h>

GLuint mine_create_shader(int type, const char *src)
{
    GLuint shader;
    int status;

    shader = glCreateShader (type);
    glShaderSource (shader, 1, &src, NULL);
    glCompileShader (shader);

    glGetShaderiv (shader, GL_COMPILE_STATUS, &status);
    if (status == GL_FALSE)
      {
        int log_len;
        char *buffer;

        glGetShaderiv (shader, GL_INFO_LOG_LENGTH, &log_len);

        buffer = g_malloc (log_len + 1);
        glGetShaderInfoLog (shader, log_len, NULL, buffer);

        g_warning ("Compile failure in %s shader:\n%s",
                   type == GL_VERTEX_SHADER ? "vertex" : "fragment",
                   buffer);

        g_free (buffer);

        glDeleteShader (shader);

        return 0;
      }

    return shader;
}
